package com.qidianit.task.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidianit.task.mapper.ProjectMapper;
import com.qidianit.task.pojo.Project;
import com.qidianit.task.service.ProjectService;
import com.qidianit.task.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author 钟思念
 * @Company
 * @Description
 * @Time 2024/9/5 22:00
 */
@Service
public class ProjectServiceImpl implements ProjectService {
    @Autowired
    private ProjectMapper projectMapper;
    //分页查询
    @Override
    public QdResult selectByPage(Project project, int page, int limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<Project> projects = projectMapper.selectList(project);
        // 创建一个PageInfo对象，构造方法中传入查询的结果集合。
        PageInfo<Project> pageInfo = new PageInfo<>(projects);
        // 将pageInfo对象设置到qdResult中
        return QdResult.success(pageInfo);
    }
    //通过id查询
    @Override
    public QdResult selectById(String projectId) {
//        Project project = projectMapper.selectById(projectId);
//        return QdResult.success(project);
        return QdResult.success(projectMapper.selectById(projectId));
    }
   //编辑更新
    @Override
    public QdResult updateProject(Project project) {
        return QdResult.success(projectMapper.updateProject(project));
    }
     //删除操作
    @Override
    public QdResult deleteProject(String projectId) {
        return QdResult.success(projectMapper.deleteById(projectId));
    }
    //归档操作
    @Override
    public QdResult pigeonholeProject(String projectId) {
        return QdResult.success(projectMapper.pigeonholeById(projectId));
    }
    //批量删除操作
    @Override
    public QdResult deleteBySelect(List<String> projectIds) {
        return QdResult.success(projectMapper.deleteBySelect(projectIds));
    }
    //批量归档操作
    @Override
    public QdResult pigeonholeBySelect(List<String> projectIds) {
        return QdResult.success(projectMapper.pigeonholeBySelect(projectIds));
    }
    //批量发布操作
    @Override
    public QdResult publishBySelect(List<String> projectIds) {
        return QdResult.success(projectMapper.publishBySelect(projectIds));
    }
    //查询删除列表
    @Override
    public QdResult selectDeleteByPage(Project project, int page, int limit) {
        // 开启分页  参数1： 页码  参数2： 每页大小
        PageHelper.startPage(page,limit);
        // 查询全部
        List<Project> projects = projectMapper.selectDeleteList(project);
        // 创建一个PageInfo对象，构造方法中传入查询的结果集合。
        PageInfo<Project> pageInfo = new PageInfo<>(projects);
        // 将pageInfo对象设置到qdResult中
        return QdResult.success(pageInfo);
    }
    //归档列表中，行功能中的恢复按钮
    @Override
    public QdResult draftById(String projectId) {
        return QdResult.success(projectMapper.updateDraftById(projectId));
    }

    //统计全部的项目
    @Override
    public QdResult allProject() {
        return QdResult.success(projectMapper.selectAllCount());
    }
    //统计我的全部项目
    @Override
    public QdResult myAllProject(Long userId) {
        return QdResult.success(projectMapper.selectMyCount(userId));
    }

}
